package com.github.MrWub.utils;

import java.lang.reflect.Field;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.file.YamlConstructor;
import org.bukkit.configuration.file.YamlRepresenter;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

public class YamlConfig extends YamlConfiguration
{
	private class DumperOptionsR extends DumperOptions {
	    @Override
	    public void setAllowUnicode(boolean allowUnicode) {
	    	super.setAllowUnicode(true);
	    }
	}
	  
	public YamlConfig() throws Exception {
		Field yamlOptionsField = YamlConfiguration.class.getDeclaredField("yamlOptions");
	    yamlOptionsField.setAccessible(true);
	    DumperOptionsR yamlOptions = new DumperOptionsR();
	    yamlOptionsField.set(this, yamlOptions);
	    
	    Field yamlRepresenterField = YamlConfiguration.class.getDeclaredField("yamlRepresenter");
	    yamlRepresenterField.setAccessible(true);
	    YamlRepresenter yamlRepresenter = new YamlRepresenter();
	    yamlRepresenterField.set(this, yamlRepresenter);
	    
	    Field yamlField = YamlConfiguration.class.getDeclaredField("yaml");
	    yamlField.setAccessible(true);
	    yamlField.set(this, new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions));
	}
}